define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resource/merchant/index' + location.search,
                    add_url: 'resource/merchant/add',
                    edit_url: 'resource/merchant/edit',
                    del_url: 'resource/merchant/del',
                    multi_url: 'resource/merchant/multi',
                    import_url: 'resource/merchant/import',
                    table: 'merchant',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE',formatter:function(value,row,index){return row.number+'<br/>'+value ; }},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'business_entity', title: __('Business_entity'), searchList: {"个体":__('个体'),"机构":__('机构')}, formatter: Table.api.formatter.normal},
                        {field: 'service_type', title: __('Service_type'), operate: 'LIKE'},
                        {field: 'service_method', title: __('Service_method'), searchList: {"采购":__('采购'),"租赁":__('租赁')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('联系方式'), operate: 'LIKE',align: 'left',formatter:function(value,row,index){return '<p>姓名:'+value + "</p><p>手机:" + row.mobile+'</p><p>QQ:'+row.qq+'</p>'; }},
                        // {field: 'mobile', title: __('Mobile')},
                        // {field: 'qq', title: __('Qq')},
                        {field: 'company', title: __('Company'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        /*{field: 'admin.nickname', title: __('Principal'), operate: 'LIKE'},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
